﻿@model CharacterModel.CharacterInfo

@{
    ViewBag.Title = "Create";
}

<script language="javascript">
    $(function () {
        $('#frm').submit(function () {
            if ($('#FirstName').val().length == 0) {
                apprise('First Name is required');
                return false;
            }
            if ($('#LastName').val().length == 0) {
                apprise('Last Name is required');
                return false;
            }
            if ($('#AgeOrDateOfBirth').val().length == 0) {
                apprise('Must enter an age or DOB');
                return false;
            }

            $(this).ajaxSubmit({
                success: function (result) {
                    if (result.ErrorMessage == null) {
                        $('#Id').val(result.SavedId);
                        apprise('Saved successfully.');
                    }
                    else
                        apprise(result.ErrorMessage);
                },
                error: function (error, status, errorThrown) {
                    apprise(errorThrown);
                }
            }
            );
            return false;
        });
    });
</script>

    <div class="SectionNavigation">
        <div class="SectionTabAll SectionTab"><a href="../Portrait/Create">Create a character</a></div>
        <div class="SectionTabAll SectionTab"><a href="../Portrait/Index">View Characters</a></div>
    </div>

<div class="ContentBorder">
    <div style="float:left;">
        <img src="../FaceDisplay/Display?faceIdentifier=@Model.Portrait.FaceIdentifier&height=200&width=200" style="float:left;"/>
    </div>

    <form id="frm" method="post" action="Save">
        @Html.HiddenFor(info => info.Id)
        @Html.HiddenFor(info => info.Portrait.Id)
        <div class="FieldBlock">
            <div>
                @Html.LabelFor(info => info.FirstName)
                @Html.TextBoxFor(info => info.FirstName)
            </div>

            <div>
                @Html.LabelFor(info => info.LastName)
                @Html.TextBoxFor(info => info.LastName)
            </div>

            <div>
                @Html.LabelFor(info => info.Occupation)
                @Html.TextBoxFor(info => info.Occupation)
            </div>

            <div>
                @Html.LabelFor(info => info.AgeOrDateOfBirth)
                @Html.TextBoxFor(info => info.AgeOrDateOfBirth)
            </div>

            <div>
                @Html.LabelFor(info => info.Hobbies)
                @Html.TextAreaFor(info => info.Hobbies)
            </div>

            <div>
                @Html.LabelFor(info => info.Education)
                @Html.TextAreaFor(info => info.Education)
            </div>
        </div>
    </form>
    <div><a onclick="javascript:$('#frm').submit(); return false;" href="#">Save</a></div>
</div>
